#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>

#define N 10

typedef void (*callback_t)(); 

void Worker()
{
   int cnt = 10;
   while(cnt)
   {
       printf("i am child process, pid: %d, ppid: %d, cnt: %d\n", getpid(), getppid(), cnt);
       sleep(1);
       cnt--;
   }
}

void createSubProcess(int n, callback_t cb)
{
    
    int i = 0;
    for(i = 0; i < n; i++)
    {
        sleep(1);
        pid_t id = fork();
        if(id == 0)
        {
            printf("create child process success: %d\n", i);
            // child
            cb();
            exit(0);
        }
    }
}

int main()
{
    //int ret = 0;
    //printf("before: %d\n", errno);
    //FILE *fp = fopen("csdn.txt", "r");
    //if(fp == NULL)
    //{
    //    printf("after: %d, error string: %s\n", errno, strerror(errno));
    //    //return 1;
    //}

    printf("Hello");
    _exit(0);
    
    //while(1)
    //{
    //    printf("i am  a process, pid: %d\n",getpid());
    //    sleep(1);
    //}
    //int a = 100;
    //a /= 0;
    
    //int *p = NULL;
    //*p = 200;

    //return 0;
    // createSubProcess(N, Worker);
    // 只有父进程走到这里 
    // sleep(100);
    //int i = 0;
    //for(i = 0; i < 200; i++)
    //{
    //    printf("%d: %s\n", i, strerror(i));
    //}

    //return 31;
}
